package udpdemo2;

import java.io.IOException;
import java.net.*;
import java.util.Date;
import java.util.Scanner;

/**
 * Created by L.jp
 * Description:
 * User: 86189
 * Date: 2022-08-08
 * Time: 23:39
 */
//UDP发送数据：数据来自于键盘录入，直到输入的数据是886，发送数据结束
    //UDP接收数据：因为接收端不知道发送端什么时候停止发送，故采用死循环接收
public class ClientDemo {
    public static void main(String[] args) throws IOException {
        Scanner scanner=new Scanner(System.in);
    
        DatagramSocket socket=new DatagramSocket();
        
        while (true){
            String data=scanner.nextLine();
            if("886".equals(data)){
                break;
            }
            byte[] bytes=data.getBytes();
            InetAddress address=InetAddress.getByName("127.0.0.1");
            int port=1000;
            DatagramPacket packet=new DatagramPacket(bytes, bytes.length,address,port);
            socket.send(packet);
        }
        socket.close();
    
    }
}
